<template>
  <el-dialog title="查看下架数据" :visible.sync="open" width="70%" append-to-body @close="cancel">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="时间范围" prop="startTime">
        <el-date-picker v-model="timeRange" range-separator="至" value-format="yyyy-MM-dd HH:mm:ss"
                        start-placeholder="开始日期" type="datetimerange" :default-time="['00:00:00', '23:59:59']"
                        end-placeholder="结束日期" placeholder="选择日期范围">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--  数据列表  -->
    <el-tabs type="border-card" v-model="tabsValue" @tab-click="tabsClick">
      <el-tab-pane v-for="(item,index) in tabList" :key="index" :label="item.label" :name="item.value">
        <el-table v-loading="loading" :data="queryList" border stripe>
          <el-table-column label="执行时间" prop="executionTime" align="center" width="200">
            <template slot-scope="scope">
              {{ scope.row.executionTime || scope.row.createTime }}
            </template>
          </el-table-column>
          <el-table-column label="速卖通id" prop="aeProductId" align="center" width="200">
            <template slot-scope="scope">
              {{ scope.row.aeProductId || scope.row.productId ? scope.row.aeProductId || scope.row.productId : "暂无" }}
            </template>
          </el-table-column>
          <el-table-column :label="tabsValue=='1'?'采集商品ID':'下架原因'" prop="collectProductId" align="center">
            <template slot-scope="scope">
              {{ tabsValue == '1' ? scope.row.collectProductId : scope.row.reason ? scope.row.reason : '暂无' }}
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="remark" align="center">
            <template slot-scope="scope">
              {{ scope.row.remark ? scope.row.remark : '暂无' }}
            </template>
          </el-table-column>
          <el-table-column label="状态" prop="status" align="center">
            <template slot-scope="scope">
              <div v-if="tabsValue=='0'">
                <!--                <span v-for="(item,index) in groundProdStatus" :key="index">{{}}</span>-->
                <dict-tag :options="groundProdStatus" :value="scope.row.status"></dict-tag>
              </div>
              <div v-else>
                <span v-if="scope.row.status == '22'">上架成功</span>
                <span v-if="scope.row.status == '23'">上架失败</span>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="tabsClick"/>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm()">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {groundProdList, offShelfProudctList} from "@/api/autoOperation/offShelf"

export default {
  name: "index",
  props: {
    configId: {
      type: String,
      default: ""
    },
    storeId: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      loading: false,
      showSearch: true,
      open: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        configId: this.configId,
        updateTime: undefined,
        createTime: undefined,
        storeId: this.storeId
      },
      queryList: [],//自运营店铺列表
      tabList: [{
        label: "下架商品列表",
        value: "0"
      }, {
        label: "下架后上架的商品",
        value: "1"
      }],
      total: 0,//数据总条数
      timeRange: "",// 时间范围
      tabsValue: "0",
      groundProdStatus: [{label: "下架成功", value: '1'},
        {label: "下架失败", value: '2'},
        {label: "上架成功", value: '3'},
        {label: "上架失败", value: '4'}],
    }
  },
  created() {
    this.getOffShelfProudctList()
  },
  methods: {
    // 获取下架后上架的商品列表
    getList() {
      this.loading = true
      this.queryParams.configId = undefined;
      groundProdList(this.queryParams).then(res => {
        this.loading = false
        let data = res.data
        this.queryList = data.list
        this.total = data.total
      })
    },
    // 获取下架商品列表
    getOffShelfProudctList() {
      this.loading = true
      this.queryParams.configId = this.configId
      offShelfProudctList(this.queryParams).then(res => {
        this.loading = false
        let data = res.data
        this.queryList = data.list
        this.total = data.total
      })
    },
    // 切换选项卡
    tabsClick(tab) {
      let index = this.tabsValue;
      if (index == '1') {
        this.getList()
      } else {
        this.getOffShelfProudctList()
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.timeRange) {
        this.queryParams.createTime = this.timeRange[0]
        this.queryParams.updateTime = this.timeRange[1]
      }
      this.tabsClick();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.timeRange = ""
      this.queryParams.createTime = ""
      this.queryParams.updateTime = ""
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    cancel() {
      this.open = false
      this.$emit('close')
    },
  }
}
</script>

<style scoped>

</style>
